﻿#region Header
//************************************************************************************
// Name: NHutils
// Description: NHutils
// Created On:  02-Aug-2011
// Created By:  Swathi
// Last Modified On:
// Last Modified By:
// Last Modified Reason:
//*************************************************************************************
#endregion Header

using System;
using System.Web;

namespace Base.Data
{
    public static class NHutils
    {
        /// <summary>
        /// Returns the correct Nhibernate Config File based on DEV, TEST or PRODUCTION
        /// </summary>
        /// <returns>Nhibernate Config File Name</returns>
        /// <remarks></remarks>
        public static string ConfigFile()
        {            
            return string.Format("NHibernate.Sqlite.{0}.config", Base.Utils.AppSettings.Instance.environment.ToLower());
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string GetHibernateConfigFileNameWithPath()
        {
            if (IsInWebContext())
            {
                return HttpContext.Current.Server.MapPath("~/Configs" + "/" + ConfigFile());
            }
            return AppDomain.CurrentDomain.BaseDirectory + "/Configs" + "/" + ConfigFile();
        }

        private static bool IsInWebContext()
        {
            return HttpContext.Current != null;
        }
    }
}